1 /* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
4 Version 1.01e, February 12th, 2005
6 Copyright (C) 1998-2005 Gilles Vollant
13 #include "ZLIB/zlib.h"
18 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
32 voidpf ZCALLBACK fopen_file_func
OF((
37 uLong ZCALLBACK fread_file_func
OF((
43 uLong ZCALLBACK fwrite_file_func
OF((
49 long ZCALLBACK ftell_file_func
OF((
53 long ZCALLBACK fseek_file_func
OF((
59 int ZCALLBACK fclose_file_func
OF((
63 int ZCALLBACK ferror_file_func
OF((
68 voidpf ZCALLBACK
fopen_file_func (opaque
, filename
, mode
)
74 const char* mode_fopen
= NULL
;
75 if ((mode
& ZLIB_FILEFUNC_MODE_READWRITEFILTER
)==ZLIB_FILEFUNC_MODE_READ
)
78 if (mode
& ZLIB_FILEFUNC_MODE_EXISTING
)
81 if (mode
& ZLIB_FILEFUNC_MODE_CREATE
)
84 if ((filename
!=NULL
) && (mode_fopen
!= NULL
))
85 file
= fopen(filename
, mode_fopen
);
90 uLong ZCALLBACK
fread_file_func (opaque
, stream
, buf
, size
)
97 ret
= (uLong
)fread(buf
, 1, (size_t)size
, (FILE *)stream
);
102 uLong ZCALLBACK
fwrite_file_func (opaque
, stream
, buf
, size
)
109 ret
= (uLong
)fwrite(buf
, 1, (size_t)size
, (FILE *)stream
);
113 long ZCALLBACK
ftell_file_func (opaque
, stream
)
118 ret
= ftell((FILE *)stream
);
122 long ZCALLBACK
fseek_file_func (opaque
, stream
, offset
, origin
)
132 case ZLIB_FILEFUNC_SEEK_CUR
:
133 fseek_origin
= SEEK_CUR
;
135 case ZLIB_FILEFUNC_SEEK_END
:
136 fseek_origin
= SEEK_END
;
138 case ZLIB_FILEFUNC_SEEK_SET
:
139 fseek_origin
= SEEK_SET
;
144 fseek((FILE *)stream
, offset
, fseek_origin
);
148 int ZCALLBACK
fclose_file_func (opaque
, stream
)
153 ret
= fclose((FILE *)stream
);
157 int ZCALLBACK
ferror_file_func (opaque
, stream
)
162 ret
= ferror((FILE *)stream
);
166 void fill_fopen_filefunc (pzlib_filefunc_def
)
167 zlib_filefunc_def
* pzlib_filefunc_def
;
169 pzlib_filefunc_def
->zopen_file
= fopen_file_func
;
170 pzlib_filefunc_def
->zread_file
= fread_file_func
;
171 pzlib_filefunc_def
->zwrite_file
= fwrite_file_func
;
172 pzlib_filefunc_def
->ztell_file
= ftell_file_func
;
173 pzlib_filefunc_def
->zseek_file
= fseek_file_func
;
174 pzlib_filefunc_def
->zclose_file
= fclose_file_func
;
175 pzlib_filefunc_def
->zerror_file
= ferror_file_func
;
176 pzlib_filefunc_def
->opaque
= NULL
;